package ex;

class Demo1 {
    int getElement(int[] arr, int index) {

        if (arr == null) {
            throw new NullPointerException("arr指向的数组不存在");
        }

        if (index < 0 || index > arr.length) {
            throw new ArrayIndexOutOfBoundsException("错误的角标," + index + "在数组中不存在");
        }
        int element = arr[index];
        return element;
    }
}

public class ExceptionDemo3 {
    public static void main(String[] args) {
        Demo1 demo = new Demo1();
        int[] arr = {1, 2, 3};
        int element = demo.getElement(null, 4);
        System.out.println("element = " + element);
        System.out.println("over");
    }
}